home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / gui / muibuilderv11.lha / muibuilder / mb / e / Mac2E.lha / Mac2E / Sources / Mac2E.e < prev    next >
Text File  |  1994-03-10  |  21KB  |  549 lines

  1. OPT OSVERSION=37
  2.  
  3. /* Traitements des erreurs */
  4. /*SF*/
  5. ENUM    OUT_OF_MEMORY,ARGS_ERROR,IO_ERROR,WRONG_PAMF,WRONG_MACRO_CALL
  6.  
  7. RAISE   OUT_OF_MEMORY   IF New()=NIL,
  8.         OUT_OF_MEMORY   IF List()=NIL,
  9.         OUT_OF_MEMORY   IF String()=NIL,
  10.         ARGS_ERROR      IF ReadArgs()=NIL,
  11.         IO_ERROR        IF Open()=NIL
  12. /*EF*/
  13.  
  14. /* Definition des constantes */
  15. /*SF*/
  16. CONST LONG_DEF_MACRO=3
  17. CONST LONG_MORCEAU_CORPS=6
  18. /*EF*/
  19.  
  20. /* Definition des objets */
  21. /*SF*/
  22. OBJECT ident_hash
  23.     ident   :LONG
  24.     hash    :LONG
  25. ENDOBJECT
  26.  
  27. OBJECT def_macro
  28.     nom         :LONG
  29.     nbre_args   :LONG
  30.     corps       :LONG
  31. ENDOBJECT
  32.  
  33. OBJECT morceau_chaine
  34.     macro           :LONG
  35.     ptr_macro       :LONG   /* si c'est une macro */
  36.     parametres      :LONG
  37.     chaine_traite   :LONG
  38.     ptr_texte       :LONG   /* si c'est une macro */
  39.     longueur        :LONG
  40. ENDOBJECT
  41. /*EF*/
  42.  
  43. /* Definition des variables globales */
  44. /*SF*/
  45. DEF table_macros[256]:ARRAY OF LONG
  46. DEF num_ligne=1
  47. /*EF*/
  48.  
  49. /**********************/
  50. /* Corps du programme */
  51. /**********************/
  52. PROC main() HANDLE
  53. /*SF*/
  54.     DEF rdargs,arguments:PTR TO LONG,nom_fichier:PTR TO LONG
  55.     DEF version,i
  56.  
  57.     Vprintf('           \c1;33;40\cMac2E\c0;31;40\c v3.0\n',[$9B,$6D,$9B,$6D])
  58.     PutStr('Copyright © 1993, Lionel Vintenat\n')
  59.     Vprintf('\c1;32;40\c---------------------------------\c0;31;40\c\n',[$9B,$6D,$9B,$6D])
  60.     version:='$VER: Mac2E 3.0 (10.3.94)'
  61.  
  62.     arguments:=[NIL,NIL,NIL]
  63.     rdargs:=ReadArgs('FROM/A,TO/A,WITH/A/M',arguments,NIL)
  64.  
  65.     FOR i:=0 TO 255 DO table_macros[i]:=NIL
  66.  
  67.     nom_fichier:=arguments[2]
  68.     WHILE nom_fichier[0] DO charger_fichier_macros(nom_fichier[0]++)
  69.  
  70.     Vprintf('Begining macro replacement in \s...\n',[arguments[0]])
  71.     traiter_source(arguments[0],arguments[1])
  72.  
  73.     FreeArgs(rdargs)
  74.  
  75. EXCEPT
  76.     SELECT exception
  77.         CASE ARGS_ERROR
  78.             PrintFault(IoErr(),NIL)
  79.         CASE OUT_OF_MEMORY
  80.             PutStr('Out of memory !\n')
  81.         CASE IO_ERROR
  82.             PrintFault(IoErr(),NIL)
  83.         CASE WRONG_PAMF
  84.             PutStr('Incorrect pre-analysed macro file !\n')
  85.     ENDSELECT
  86.  
  87.     IF rdargs THEN FreeArgs(rdargs)
  88.  
  89.     CleanUp(100)
  90. ENDPROC
  91. /*EF*/
  92.  
  93. /*******************************************/
  94. /* Charge un fichier de macros pre-analyse */
  95. /*******************************************/
  96. PROC charger_fichier_macros(nom_fichier:PTR TO CHAR)
  97. /*SF*/
  98.     DEF fichier,long_fichier,adr_fichier
  99.     DEF liste_macros_hash:PTR TO def_macro
  100.     DEF nbre_macros,nbre,ptr_chaine:PTR TO CHAR,i,j
  101.  
  102.     Vprintf('Loading pre-analysed macro file \s...\n',[nom_fichier])
  103.     fichier:=Open(nom_fichier,OLDFILE)
  104.     long_fichier:=FileLength(nom_fichier)
  105.     adr_fichier:=New(long_fichier)
  106.     Read(fichier,adr_fichier,long_fichier)
  107.     Close(fichier)
  108.  
  109.     ptr_chaine:=adr_fichier
  110.     IF StrCmp(ptr_chaine,'PreMac2E_Save_Format_V1.0',ALL)
  111.         ptr_chaine:=ptr_chaine+26   /* ptr_chaine:=ptr_chaine+StrLen('PreMac2E_Save_Format_V1.0')+1 */
  112.         FOR i:=0 TO 255
  113.             nbre_macros:=Char(ptr_chaine++)*256+Char(ptr_chaine++)
  114.             liste_macros_hash:=table_macros[i]
  115.             FOR j:=1 TO nbre_macros
  116.                 liste_macros_hash:=Link(List(LONG_DEF_MACRO),liste_macros_hash)
  117.                 nbre:=Char(ptr_chaine++)
  118.                 liste_macros_hash.nom:=ptr_chaine
  119.                 ptr_chaine:=ptr_chaine+nbre+1
  120.                 liste_macros_hash.nbre_args:=Char(ptr_chaine++)
  121.                 nbre:=Char(ptr_chaine++)*256+Char(ptr_chaine++)
  122.                 liste_macros_hash.corps:=ptr_chaine
  123.                 ptr_chaine:=ptr_chaine+nbre+1
  124.             ENDFOR
  125.             table_macros[i]:=liste_macros_hash
  126.         ENDFOR
  127.     ELSE
  128.         Raise(WRONG_PAMF)
  129.     ENDIF
  130. ENDPROC
  131. /*EF*/
  132.  
  133. /************************************************************************************/
  134. /* Fait une passe de remplacement des macros du fichier source vers celui d'arrivee */
  135. /************************************************************************************/
  136. PROC traiter_source(fichier_source:PTR TO CHAR,fichier_destination:PTR TO CHAR) HANDLE
  137. /*SF*/
  138.     DEF fichier,adr_fichier,long_fichier,fin_fichier
  139.     DEF deb_phrase,fin_phrase,ident_courant:ident_hash
  140.     DEF ptr_macro:PTR TO def_macro,args_macro:PTR TO LONG
  141.     DEF car,pointeur_car:PTR TO CHAR,i
  142.  
  143.     fichier:=Open(fichier_source,OLDFILE)
  144.     long_fichier:=FileLength(fichier_source)
  145.     adr_fichier:=New(long_fichier)
  146.     fin_fichier:=adr_fichier+long_fichier
  147.     Read(fichier,adr_fichier,long_fichier)
  148.     Close(fichier)
  149.  
  150.     fichier:=Open(fichier_destination,NEWFILE)
  151.  
  152.     pointeur_car:=adr_fichier
  153.     deb_phrase:=adr_fichier
  154.     WHILE pointeur_car<fin_fichier
  155.  
  156.             /* IF (car:=Char(pointeur_car++))=10 THEN INC num_ligne */
  157.         MOVE.L  pointeur_car,A0
  158.         CLR.L   D0
  159.         MOVE.B  (A0)+,D0
  160.         MOVE.L  A0,pointeur_car
  161.         CMP.B   #10,D0
  162.         BNE.B   ts_non_add_ligne1
  163.         INC num_ligne
  164.         ts_non_add_ligne1:
  165.         MOVE.L  D0,car
  166.  
  167.         SELECT car
  168.             CASE "/"
  169.                     /*  IF (Char(pointeur_car)="*") AND (pointeur_car<fin_fichier)
  170.                             INC pointeur_car
  171.                             level_comment:=1
  172.                             WHILE (pointeur_car<fin_fichier) AND (level_comment>0)
  173.                                 IF (car:=Char(pointeur_car++))=10 THEN INC num_ligne 
  174.                                 SELECT car
  175.                                     CASE "*"
  176.                                         IF (pointeur_car<fin_fichier) AND (Char(pointeur_car)="/")
  177.                                             DEC level_comment
  178.                                             INC pointeur_car
  179.                                         ENDIF
  180.                                     CASE "/"
  181.                                         IF (pointeur_car<fin_fichier) AND (Char(pointeur_car)="*")
  182.                                             INC level_comment
  183.                                             INC pointeur_car
  184.                                         ENDIF
  185.                                 ENDSELECT
  186.                             ENDWHILE
  187.                         ENDIF */
  188.  
  189.                 MOVE.L  pointeur_car,A0
  190.                 MOVE.L  fin_fichier,A1
  191.                 CMPA.L  A0,A1
  192.                 BEQ.W   ts_fin_while2
  193.                 MOVE.B  (A0),D0
  194.                 CMP.B   #"*",D0
  195.                 BNE.W   ts_fin_while2
  196.                 ADDQ.L  #1,A0
  197.                 MOVE.L  #1,D2
  198.                 ts_while1:
  199.                     TST.L   D2
  200.                     BEQ.B   ts_fin_while1
  201.                     CMPA.L  A0,A1
  202.                     BEQ.B   ts_fin_while1
  203.                     ts_while2:
  204.                     MOVE.B  (A0)+,D0
  205.                     CMP.B   #10,D0
  206.                     BNE.B   ts_non_add_ligne2
  207.                     INC num_ligne
  208.                     ts_non_add_ligne2:
  209.                     CMPA.L  A0,A1
  210.                     BEQ.B   ts_fin_while1
  211.                     CMP.B   #"*",D0
  212.                     BNE.B   ts_non_etoile
  213.                     MOVE.B  (A0),D1
  214.                     CMP.B   #"/",D1
  215.                     BNE.B   ts_while2
  216.                     SUBQ.L  #1,D2
  217.                     ADDQ.L  #1,A0
  218.                     BRA.B   ts_while1
  219.                     ts_non_etoile:
  220.                     CMP.B   #"/",D0
  221.                     BNE.B   ts_while2
  222.                     MOVE.B  (A0),D1
  223.                     CMP.B   #"*",D1
  224.                     BNE.B   ts_while2
  225.                     ADDQ.L  #1,D2
  226.                     ADDQ.L  #1,A0
  227.                     BRA.B   ts_while1
  228.                 ts_fin_while1:
  229.                 MOVE.L  A0,pointeur_car
  230.                 ts_fin_while2:
  231.  
  232.             CASE "'"
  233.                     /*  IF (Char(pointeur_car-2)<>34) OR ((pointeur_car-2)<adr_fichier)
  234.                             WHILE (pointeur_car<fin_fichier) AND ((car:=Char(pointeur_car++))<>"'")
  235.                                 IF car=10 THEN INC num_ligne
  236.                             ENDWHILE
  237.                         ENDIF */
  238.  
  239.                 MOVE.L  pointeur_car,A0
  240.                 MOVE.L  fin_fichier,A1
  241.                 CMPI.B  #34,-2(A0)
  242.                 BNE.B   ts_while
  243.                 MOVE.L  adr_fichier,A2
  244.                 ADDQ.L  #1,A2
  245.                 CMPA.L  A0,A2
  246.                 BNE.B   ts_fin_while_bis
  247.                 ts_while:
  248.                 CMPA.L  A0,A1
  249.                 BEQ.B   ts_fin_while
  250.                 MOVE.B  (A0)+,D0
  251.                 CMP.B   #10,D0
  252.                 BNE.B   ts_non_add_ligne3
  253.                 INC num_ligne
  254.                 ts_non_add_ligne3:
  255.                 CMP.B   #"'",D0
  256.                 BNE.B   ts_while
  257.                 ts_fin_while:
  258.                 MOVE.L  A0,pointeur_car
  259.                 ts_fin_while_bis:
  260.  
  261.             DEFAULT
  262.                 DEC pointeur_car
  263.                 fin_phrase:=pointeur_car
  264.                 pointeur_car:=chercher_identificateur_hash(pointeur_car,fin_fichier,ident_courant)
  265.                 IF ident_courant.ident
  266.                     IF ptr_macro:=est_ce_macro(ident_courant.ident,ident_courant.hash)
  267.                         Write(fichier,deb_phrase,fin_phrase-deb_phrase)
  268.                         IF ptr_macro.nbre_args
  269.                             args_macro:=List(ptr_macro.nbre_args)
  270.                             pointeur_car:=recuperer_args_macro(pointeur_car,fin_fichier,ptr_macro,args_macro)
  271.                             FOR i:=0 TO ptr_macro.nbre_args-1 DO args_macro[i]:=traiter_chaine(args_macro[i])
  272.                             placer_corps_macro(fichier,ptr_macro,args_macro)
  273.                         ELSE
  274.                             IF (Char(pointeur_car)<>"(") OR (pointeur_car=fin_fichier)
  275.                                 Write(fichier,ptr_macro.corps,StrLen(ptr_macro.corps))
  276.                             ELSE
  277.                                 Vprintf('Wrong number of args in \s call in line \d !\n',[ptr_macro.nom,num_ligne])
  278.                                 Raise(WRONG_MACRO_CALL)
  279.                             ENDIF
  280.                         ENDIF
  281.                         deb_phrase:=pointeur_car
  282.                     ENDIF
  283.                 ELSE
  284.                     INC pointeur_car
  285.                 ENDIF
  286.         ENDSELECT
  287.     ENDWHILE
  288.     Write(fichier,deb_phrase,pointeur_car-deb_phrase)
  289.  
  290.     Close(fichier)
  291.  
  292. EXCEPT
  293.     Close(fichier)
  294.     Raise(WRONG_MACRO_CALL)
  295. ENDPROC
  296. /*EF*/
  297.  
  298. /********************************************************************************************/
  299. /* Retourne l'identificateur pointe actuellement dans le fichier, avec sa valeur hash-codee */
  300. /********************************************************************************************/
  301. PROC chercher_identificateur_hash(pointeur_car:PTR TO CHAR,fin_fichier,ident_reconnu:PTR TO ident_hash)
  302. /*SF*/
  303.     DEF debut_ident,long_ident,hash
  304.  
  305.     debut_ident:=pointeur_car
  306.     MOVE.L  pointeur_car,A0
  307.     MOVE.L  fin_fichier,A1
  308.     CLR.L   D1
  309. /* WHILE (caractere(Char(pointeur_car))) AND (pointeur_car<fin_fichier) DO INC pointeur_car */
  310.     cih_while:
  311.         CMPA.L  A1,A0           /* pointeur_car=fin_fichier ? */
  312.         BEQ.B   cih_fin_while
  313.         MOVE.B  (A0)+,D0
  314.         ADD.B   D0,D1
  315.         CMP.B   #"_",D0         /* Char(pointeur_car)="_" ? */
  316.         BEQ.B   cih_while
  317.         CMP.B   #"A",D0         /* Char(pointeur_car)E["A".."Z"] ?*/
  318.         BCS.B   cih_non_majuscule
  319.         CMP.B   #"Z",D0
  320.         BLS.B   cih_while
  321.     cih_non_majuscule:
  322.         CMP.B   #"a",D0         /* Char(pointeur_car)E["a".."z"] ?*/
  323.         BCS.B   cih_non_minuscule
  324.         CMP.B   #"z",D0
  325.         BLS.B   cih_while
  326.     cih_non_minuscule:
  327.         CMP.B   #"0",D0         /* Char(pointeur_car)E["0".."9"] ?*/
  328.         BCS.B   cih_non_chiffre
  329.         CMP.B   #"9",D0
  330.         BLS.B   cih_while
  331.     cih_non_chiffre:
  332.         SUBQ.L  #1,A0
  333.         SUB.B   D0,D1
  334.     cih_fin_while:
  335.         MOVE.L  A0,pointeur_car
  336.         MOVE.L  D1,hash
  337.     IF long_ident:=(pointeur_car-debut_ident)
  338.         ident_reconnu.ident:=String(long_ident)
  339.         StrCopy(ident_reconnu.ident,debut_ident,long_ident)
  340.         ident_reconnu.hash:=hash
  341.     ELSE
  342.         ident_reconnu.ident:=NIL
  343.     ENDIF
  344. ENDPROC pointeur_car
  345. /*EF*/
  346.  
  347. /****************************************************************************************/
  348. /* Retourne un pointeur sur le descriptif de la macro dont le nom est passe en argument */
  349. /****************************************************************************************/
  350. PROC est_ce_macro(nom_macro:PTR TO CHAR,hash_code)
  351. /*SF*/
  352.     DEF liste_macros_hash:PTR TO def_macro
  353.  
  354.     liste_macros_hash:=table_macros[hash_code]
  355.     WHILE liste_macros_hash DO IF StrCmp(liste_macros_hash.nom,nom_macro,ALL) THEN RETURN liste_macros_hash ELSE liste_macros_hash:=Next(liste_macros_hash)
  356.  
  357. ENDPROC NIL 
  358. /*EF*/
  359.  
  360. /*******************************************************/
  361. /* Retourne un tableau des arguments passes a la macro */
  362. /*******************************************************/
  363. PROC recuperer_args_macro(pointeur_car:PTR TO CHAR,fin_chaine,ptr_macro:PTR TO def_macro,parametres:PTR TO LONG)
  364. /*SF*/
  365.     DEF car,encore=TRUE,level=0
  366.     DEF deb_arg,long_arg,num_arg
  367.  
  368.     num_arg:=ptr_macro.nbre_args-1
  369.     IF pointeur_car<fin_chaine
  370.         IF (car:=Char(pointeur_car++))="("
  371.             deb_arg:=pointeur_car
  372.             WHILE (pointeur_car<fin_chaine) AND encore
  373.                 car:=Char(pointeur_car++)
  374.                 SELECT car
  375.                     CASE 10
  376.                         Vprintf('Unexpected end of line in \s call in line \d !\n',[ptr_macro.nom,num_ligne])
  377.                         Raise(WRONG_MACRO_CALL)
  378.                     CASE 34
  379.                         pointeur_car:=pointeur_car+2
  380.                     CASE ","
  381.                         IF level=0
  382.                             long_arg:=pointeur_car-deb_arg-1
  383.                             parametres[num_arg]:=String(long_arg)
  384.                             StrCopy(parametres[num_arg],deb_arg,long_arg)
  385.                             DEC num_arg
  386.                             deb_arg:=pointeur_car
  387.                             IF num_arg<0
  388.                                 Vprintf('Wrong number of args in \s call in line \d !\n',[ptr_macro.nom,num_ligne])
  389.                                 Raise(WRONG_MACRO_CALL)
  390.                             ENDIF
  391.                         ENDIF
  392.                     CASE "("
  393.                         INC level
  394.                     CASE ")"
  395.                         IF level
  396.                             DEC level
  397.                         ELSE
  398.                             long_arg:=pointeur_car-deb_arg-1
  399.                             parametres[num_arg]:=String(long_arg)
  400.                             StrCopy(parametres[num_arg],deb_arg,long_arg)
  401.                             DEC num_arg
  402.                             encore:=FALSE
  403.                         ENDIF
  404.                     CASE "'"
  405.                         WHILE (pointeur_car<fin_chaine) AND (Char(pointeur_car)<>"'") DO INC pointeur_car
  406.                         INC pointeur_car
  407.                 ENDSELECT
  408.             ENDWHILE
  409.             IF encore
  410.                 Vprintf('Unexpected end of file in the middle of \s call in line \d !\n',[ptr_macro.nom,num_ligne])
  411.                 Raise(WRONG_MACRO_CALL)
  412.             ENDIF
  413.         ELSE
  414.             DEC pointeur_car
  415.             IF car=10 THEN DEC num_ligne
  416.         ENDIF
  417.     ENDIF
  418.     IF num_arg>=0
  419.         Vprintf('Wrong number of args in \s call in line \d !\n',[ptr_macro.nom,num_ligne])
  420.         Raise(WRONG_MACRO_CALL)
  421.     ENDIF
  422. ENDPROC pointeur_car
  423. /*EF*/
  424.  
  425. /****************************************************************************************/
  426. /* Remplace dans chaine_avant toutes les macros par leur corps et retourne chaine_apres */
  427. /****************************************************************************************/
  428. PROC traiter_chaine(chaine_avant:PTR TO CHAR)
  429. /*SF*/
  430.     DEF chaine_apres:PTR TO CHAR,long_chaine_apres=0,fin_chaine_avant
  431.     DEF nom_ident:ident_hash,ptr_macro:PTR TO def_macro,long_temp
  432.     DEF deb_morceau,morceaux:PTR TO morceau_chaine,morceaux_temp:PTR TO morceau_chaine
  433.     DEF morceau:PTR TO morceau_chaine,parametres:PTR TO LONG
  434.     DEF pointeur_car,pointeur_car_temp,i
  435.  
  436.     fin_chaine_avant:=chaine_avant+EstrLen(chaine_avant)
  437.     morceaux:=NIL
  438.     pointeur_car:=chaine_avant
  439.     deb_morceau:=chaine_avant
  440.     WHILE pointeur_car<fin_chaine_avant
  441.         pointeur_car_temp:=pointeur_car
  442.         pointeur_car:=chercher_identificateur_hash(pointeur_car,fin_chaine_avant,nom_ident)
  443.         IF nom_ident.ident
  444.             IF ptr_macro:=est_ce_macro(nom_ident.ident,nom_ident.hash)
  445.                 IF long_temp:=(pointeur_car_temp-deb_morceau)
  446.                     morceaux:=Link(List(LONG_MORCEAU_CORPS),morceaux)
  447.                     morceaux.macro:=FALSE
  448.                     morceaux.ptr_texte:=deb_morceau
  449.                     morceaux.longueur:=long_temp
  450.                     long_chaine_apres:=long_chaine_apres+morceaux.longueur
  451.                 ENDIF
  452.                 morceaux:=Link(List(LONG_MORCEAU_CORPS),morceaux)
  453.                 morceaux.macro:=TRUE
  454.                 morceaux.ptr_macro:=ptr_macro
  455.                 IF ptr_macro.nbre_args
  456.                     morceaux.parametres:=List(ptr_macro.nbre_args)
  457.                     pointeur_car:=recuperer_args_macro(pointeur_car,fin_chaine_avant,ptr_macro,morceaux.parametres)
  458.                 ELSE
  459.                     IF (Char(pointeur_car)="(") AND (pointeur_car<>fin_chaine_avant)
  460.                         Vprintf('Wrong number of args in \s call in line \d !\n',[ptr_macro.nom,num_ligne])
  461.                         Raise(WRONG_MACRO_CALL)
  462.                     ENDIF
  463.                 ENDIF
  464.                 deb_morceau:=pointeur_car
  465.             ENDIF
  466.         ELSE
  467.             IF (Char(pointeur_car)="'") AND ((Char(pointeur_car-1)<>34) OR ((pointeur_car-1)<chaine_avant))
  468.                 INC pointeur_car
  469.                 WHILE (pointeur_car<fin_chaine_avant) AND (Char(pointeur_car)<>"'") DO INC pointeur_car
  470.             ENDIF
  471.             INC pointeur_car
  472.         ENDIF
  473.     ENDWHILE
  474.     IF long_temp:=(pointeur_car-deb_morceau)
  475.         morceaux:=Link(List(LONG_MORCEAU_CORPS),morceaux)
  476.         morceaux.macro:=FALSE
  477.         morceaux.ptr_texte:=deb_morceau
  478.         morceaux.longueur:=long_temp
  479.         long_chaine_apres:=long_chaine_apres+morceaux.longueur
  480.     ENDIF
  481.     morceaux_temp:=NIL
  482.     WHILE morceaux
  483.         morceau:=morceaux
  484.         morceaux:=Next(morceaux)
  485.         morceaux_temp:=Link(morceau,morceaux_temp)
  486.         IF morceau.macro
  487.             ptr_macro:=morceau.ptr_macro
  488.             IF ptr_macro.nbre_args
  489.                 parametres:=morceau.parametres
  490.                 FOR i:=0 TO ptr_macro.nbre_args-1 DO parametres[i]:=traiter_chaine(parametres[i])
  491.                 morceau.chaine_traite:=traiter_corps_macro(ptr_macro,parametres)
  492.             ELSE
  493.                 morceau.chaine_traite:=String(StrLen(ptr_macro.corps))
  494.                 StrCopy(morceau.chaine_traite,ptr_macro.corps,ALL)
  495.             ENDIF
  496.             long_chaine_apres:=long_chaine_apres+EstrLen(morceau.chaine_traite)
  497.         ENDIF
  498.     ENDWHILE
  499.     chaine_apres:=String(long_chaine_apres)
  500.     morceaux:=morceaux_temp
  501.     WHILE morceaux
  502.         IF morceaux.macro THEN StrAdd(chaine_apres,morceaux.chaine_traite,ALL) ELSE StrAdd(chaine_apres,morceaux.ptr_texte,morceaux.longueur)
  503.         morceaux:=Next(morceaux)
  504.     ENDWHILE
  505. ENDPROC chaine_apres
  506. /*EF*/
  507.  
  508. /*************************************************************/
  509. /* Retourne le corps de la macro en remplacant les arguments */
  510. /*************************************************************/
  511. PROC traiter_corps_macro(ptr_macro:PTR TO def_macro,parametres:PTR TO LONG)
  512. /*SF*/
  513.     DEF long_corps,long_corps_temp,long_args:PTR TO LONG
  514.     DEF corps_macro_expandee,car,pos:PTR TO CHAR,i
  515.  
  516.     long_args:=List(ptr_macro.nbre_args)
  517.     FOR i:=0 TO ptr_macro.nbre_args-1 DO long_args[i]:=EstrLen(parametres[i])
  518.     long_corps:=StrLen(ptr_macro.corps)
  519.     long_corps_temp:=long_corps
  520.     pos:=ptr_macro.corps
  521.     FOR i:=0 TO long_corps_temp-1 DO IF (car:=pos[i])>=128 THEN long_corps:=long_corps+long_args[car-128]-1
  522.     corps_macro_expandee:=String(long_corps)
  523.     pos:=ptr_macro.corps
  524.     FOR i:=0 TO long_corps_temp-1 DO IF (car:=pos[i])>=128 THEN StrAdd(corps_macro_expandee,parametres[car-128],ALL) ELSE StrAdd(corps_macro_expandee,(pos+i),1)
  525. ENDPROC corps_macro_expandee
  526. /*EF*/
  527.  
  528. /**************************************************************************/
  529. /* Ecrit le corps de la macro dans le fichier en remplacant les arguments */
  530. /**************************************************************************/
  531. PROC placer_corps_macro(fichier,ptr_macro:PTR TO def_macro,parametres:PTR TO LONG)
  532. /*SF*/
  533.     DEF car,pos:PTR TO CHAR,deb:PTR TO CHAR
  534.  
  535.         deb:=ptr_macro.corps
  536.         pos:=ptr_macro.corps
  537.         WHILE (car:=Char(pos))<>0
  538.             IF car>=128
  539.                 Write(fichier,deb,pos-deb)
  540.                 Write(fichier,parametres[car-128],EstrLen(parametres[car-128]))
  541.                 deb:=pos+1
  542.             ENDIF
  543.             INC pos
  544.         ENDWHILE
  545.         Write(fichier,deb,pos-deb)
  546. ENDPROC
  547. /*EF*/
  548.  
  549.